package queue;

/*
class MyCircularQueue {
    int[] elem;
    int front;
    int rear;
    public MyCircularQueue(int k) {
        elem=new int[k+1];
    }

    public boolean enQueue(int value) {
        if(isFull()){
            return false;
        }
        elem[rear]=value;
        rear=(rear+1)%elem.length;
        return true;
    }

    public boolean deQueue() {
        if(isEmpty()){
            return false;
        }
        front=(front+1)%elem.length;
        return true;
    }

    public int Front() {
        if(isEmpty()){
            return -1;
        }
        return elem[front];
    }

    public int Rear() {
        if(isEmpty()){
            return -1;
        }
        return elem[(rear-1+elem.length)%elem.length];
    }

    public boolean isEmpty() {
        return front==rear;
    }

    public boolean isFull() {
        if((rear+1)% elem.length==front){
            return true;
        }
        return false;
    }
}*/



/*
class MyCircularQueue {
    int[] elem;
    int front;
    int rear;
    int size;
    public MyCircularQueue(int k) {
        elem=new int[k];
    }

    public boolean enQueue(int value) {
        if(isFull()){
            return false;
        }
        elem[rear]=value;
        rear=(rear+1)%elem.length;
        size++;
        return true;
    }

    public boolean deQueue() {
        if(isEmpty()){
            return false;
        }
        front=(front+1)%elem.length;
        size--;
        return true;
    }

    public int Front() {
        if(isEmpty()){
            return -1;
        }
       return elem[front];
    }

    public int Rear() {
        if(isEmpty()){
            return -1;
        }
        return elem[(rear-1+elem.length)%elem.length];
    }

    public boolean isEmpty() {
        return size==0;
    }

    public boolean isFull() {
        return size==elem.length;
    }
}*/


class MyCircularQueue {
    int[] elem;
    int front;
    int rear;
    boolean IsFull;

    public MyCircularQueue(int k) {
        elem = new int[k];
    }

    public boolean enQueue(int value) {
        if (isFull()) {
            return false;
        }
        elem[rear] = value;
        rear = (rear + 1) % elem.length;
        if (rear == front) {
            IsFull = true;
        }
        return true;
    }

    public boolean deQueue() {
        if (isEmpty()) {
            return false;
        }
        front = (front + 1) % elem.length;
        IsFull = false;
        return true;
    }

    public int Front() {
        if (isEmpty()) {
            return -1;
        }
        return elem[front];
    }

    public int Rear() {
        if (isEmpty()) {
            return -1;
        }
        return elem[(rear - 1 + elem.length) % elem.length];
    }

    public boolean isEmpty() {
        if (!IsFull && front == rear) {
            return true;
        }
        return false;
    }
    public boolean isFull () {
        if (IsFull && front == rear) {
            return true;
        }
        return false;
    }

}